Skip to content

[Datasets] Add PyArrow docs#1839

Merged
lhoestq merged 4 commits into
mainfrom
add-pyarrow-docs
Jul 24, 2025
Merged

[Datasets] Add PyArrow docs#1839
lhoestq merged 4 commits into
mainfrom
add-pyarrow-docs

Conversation

@lhoestq

@lhoestq lhoestq commented Jul 15, 2025

Copy link
Copy Markdown
Member

pyarrow 21 will be out soon and has an official HF integration :)

It also includes Parquet CDC for efficient Xet deduplication for datasets

cc @kszucs

@lhoestq
lhoestq requested a review from davanstrien July 15, 2025 16:20
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@julien-c

Copy link
Copy Markdown
Member

nice!

Comment thread docs/hub/datasets-libraries.md Outdated
pq.write_table(table_test , "hf://datasets/username/my_dataset/test.parquet", use_content_defined_chunking=True)
```

We use `use_content_defined_chunking=True` to enable faster uploads and downloads from Hugging Face thanks to Xet deduplication (it requires `pyarrow>=21.0`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think we could ask them to turn it on by default?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hard to say, wdyt @kszucs ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe in case of a hf:// URI but that could be fragile to implement since filesystem objects can be passed as well.
I would rather consider the flavor argument https://arrow.apache.org/docs/python/generated/pyarrow.parquet.write_table.html

pq.write_table(table_test , "hf://datasets/username/my_dataset/test.parquet", flavor="huggingface")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that CDC has a slight performance overhead, so turning it on by default would make sense if we can infer that the targeted filesystem can use it for deduplication.

Comment thread docs/hub/datasets-pyarrow.md Outdated

@davanstrien davanstrien left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool! Think this could also be helpful for people already heavily using Arrow for science datasets to understand how to get them on the Hub.

Comment thread docs/hub/datasets-pyarrow.md Outdated
Comment thread docs/hub/datasets-pyarrow.md Outdated
Comment thread docs/hub/datasets-pyarrow.md Outdated
Comment thread docs/hub/datasets-pyarrow.md Outdated

To load a file from Hugging Face, the path needs to start with `hf://`. For example, the path to the [stanfordnlp/imdb](https://huggingface.co/datasets/stanfordnlp/imdb) dataset repository is `hf://datasets/stanfordnlp/imdb`. The dataset on Hugging Face contains multiple Parquet files. The Parquet file format is designed to make reading and writing data frames efficient, and to make sharing data across data analysis languages easy. Here is how to load the file `plain_text/train-00000-of-00001.parquet` as a pyarrow Table (it requires `pyarrow>=21.0`):

```python

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe

Suggested change
```python
```pycon

(see https://pygments.org/docs/lexers/#pygments.lexers.python.PythonConsoleLexer for example)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait what Oo

I might keep it that way for now for consistency and update the whole docs later if it's really a thing :o

Comment thread docs/hub/datasets-pyarrow.md Outdated
lhoestq and others added 3 commits July 24, 2025 11:17
Co-authored-by: Daniel van Strien <davanstrien@users.noreply.github.com>
Co-authored-by: Julien Chaumond <julien@huggingface.co>
@lhoestq

lhoestq commented Jul 24, 2025

Copy link
Copy Markdown
Member Author

thanks for the reviews :) I took your comments into account

@lhoestq
lhoestq merged commit 1d8c6cf into main Jul 24, 2025
2 checks passed
@lhoestq
lhoestq deleted the add-pyarrow-docs branch July 24, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants